#include "displayitem.h"
#include <QDeclarativeItem>
#include <QX11EmbedContainer>
#include <QtDeclarative>
#include <QProcess>
#include <QtGui>
#include <QDebug>

DisplayItem::DisplayItem(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
{
    container = new QWidget;//(NULL);
    container->setMinimumSize(320, 240);

    qDebug() << "OK";
    // if I execute container->show(); here, I get the video on a new window
    //container->show();

    process = new QProcess(this);
    QString executable("/usr/bin/mplayer");
    //QString executable("/usr/bin/minitube");
    QStringList arguments;


    arguments << "-wid";
    arguments << QString::number(container->winId());
    //arguments << "-slave";
    //arguments << "-quiet";
    arguments << "/home/emmanuel/bionicexample.wmv";

    qDebug() << "exec executable: " << executable;
    qDebug() << "arg: " << arguments;
    process->start(executable, arguments);
    //qDebug() << "lounched";
    if (!process->waitForStarted(-1)) {
        qDebug() << "Start failed:" << process->errorString();

    }else {
        QString sResponse = process->readAll();
        qDebug() << "Succeed output:" << sResponse;
    }
    qDebug() << "finished";
    //process->waitForStarted(-1);
    qDebug() << "startded";
    proxy = new QGraphicsProxyWidget(this);
    proxy->setWidget(container);
    proxy->adjustSize();
    //proxy->setPos(-container->sizeHint().width()/2, -container->sizeHint().height()/2);
    qDebug() << "OK-";
    // if I execute container->show(); here, I get nothing visible
    //container->show();
}
